package com.woniu.user.controller;

import com.woniu.common.entity.ResponseResult;
import com.woniu.user.entity.Complain;
import com.woniu.user.service.ComplainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author author
 * @create 2021/5/19
 */
@RequestMapping("/complain")
@RestController
public class ComplainController {

    @Autowired
    ComplainService complainService;

    @GetMapping("/all")
    public ResponseResult<List<Complain>> selectAllComplain(Integer status) {
        return new ResponseResult<>(200, null, "ok", complainService.selectAllComplain(status), null);
    }

    @PostMapping("/addComplain")
    public ResponseResult<String> addComplain(@RequestBody Complain complain) {

        if (complainService.addComplain(complain)) {

            return new ResponseResult<>(200, null, "投诉成功", null, null);

        }

        return new ResponseResult<>(500, null, "投诉失败，请重新填写", null, null);
    }

    @PostMapping("/add")
    public ResponseResult<String> updateStatusById(Integer id) {

        if (complainService.updateStatus(id)) {

            return new ResponseResult<>(200, null, "新增成功", null, null);

        }

        return new ResponseResult<>(500, null, "修改失败，请稍后重试", null, null);
    }
}
